package com.beauty.dressing.module.mine.activity;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.beauty.dressing.R;
import com.beauty.dressing.common.base.BaseActivity;
import com.beauty.dressing.common.bean.DataBean;
import com.beauty.dressing.common.bean.LeaseBean;
import com.beauty.dressing.common.utils.Constants;
import com.beauty.dressing.module.mine.persenter.MyLeaseControl;
import com.beauty.dressing.module.mine.persenter.MyLeasePresenter;
import com.beauty.dressing.rxandroid.api.ApiManager;
import com.xiaolanba.commonlib.fresco.FrescoUtil;

public class MyInRentActivity extends BaseActivity {
    TextView throw_content, leasse_return_content, leased_time, lease_status, title;
    LeaseBean bean;
    SimpleDraweeView image;

    @Override
    public void setContentView() {
        setContentView(R.layout.activity_my_inrent);
    }

    @Override
    public void findView() {
        TextView title_txt = findViewById(R.id.title_txt);
        title_txt.setText("我的租赁");
        findViewById(R.id.left_img_btn).setOnClickListener(this);
        throw_content = findViewById(R.id.throw_content);
        leasse_return_content = findViewById(R.id.leasse_return_content);
        findViewById(R.id.tv_discard).setOnClickListener(this);
        findViewById(R.id.tv_surrender).setOnClickListener(this);

        image = findViewById(R.id.image);
        leased_time = findViewById(R.id.leased_time);
        lease_status = findViewById(R.id.lease_status);
        title = findViewById(R.id.title);

    }

    @Override
    public void initData() {
        myLeasePresenter.explain();
        if (getIntent().getSerializableExtra(Constants.ACTIVITYDATA) != null) {
            bean = (LeaseBean) getIntent().getSerializableExtra(Constants.ACTIVITYDATA);
            title.setText(bean.getLease_name());
            leased_time.setText(bean.getLease_days() + "天");
            lease_status.setText("" + bean.getLease_name());
            FrescoUtil.loadImage(image, ApiManager.HEAR_URL + bean.getImage());
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_discard:
                startActivity(new Intent(context, ProtocolActivity.class).putExtra(Constants.AGREEMENT, "2").putExtra("data", bean));
                break;
            case R.id.tv_surrender:
                startActivity(new Intent(context, ProtocolActivity.class).putExtra(Constants.AGREEMENT, "1").putExtra("data", bean));
                break;
            case R.id.left_img_btn:
                this.finish();
                break;
        }
    }

    MyLeasePresenter myLeasePresenter = new MyLeasePresenter(new MyLeaseControl() {
        @Override
        public void onExplain(boolean isSuccess, int code, String message, DataBean bean) {
            super.onExplain(isSuccess, code, message, bean);
            throw_content.setText(bean.getThrow_explain());
            leasse_return_content.setText(bean.getLeasse_return_explain());
        }
    });
}
